﻿using System;

namespace UniRx.Operators
{
	// Token: 0x020002D1 RID: 721
	internal class RangeObservable : OperatorObservableBase<int>
	{
		// Token: 0x06000F7C RID: 3964 RVA: 0x00047D10 File Offset: 0x00046110
		public RangeObservable(int start, int count, IScheduler scheduler) : base(scheduler == Scheduler.CurrentThread)
		{
			if (count < 0)
			{
				throw new ArgumentOutOfRangeException("count < 0");
			}
			this.start = start;
			this.count = count;
			this.scheduler = scheduler;
		}

		// Token: 0x06000F7D RID: 3965 RVA: 0x00047D48 File Offset: 0x00046148
		protected override IDisposable SubscribeCore(IObserver<int> observer, IDisposable cancel)
		{
			//RangeObservable.<SubscribeCore>c__AnonStorey1 <SubscribeCore>c__AnonStorey = new RangeObservable.<SubscribeCore>c__AnonStorey1();
			//<SubscribeCore>c__AnonStorey.observer = observer;
			//<SubscribeCore>c__AnonStorey.$this = this;
			//<SubscribeCore>c__AnonStorey.observer = new RangeObservable.Range(<SubscribeCore>c__AnonStorey.observer, cancel);
			//if (this.scheduler == Scheduler.Immediate)
			//{
			//	for (int j = 0; j < this.count; j++)
			//	{
			//		int value = this.start + j;
			//		<SubscribeCore>c__AnonStorey.observer.OnNext(value);
			//	}
			//	<SubscribeCore>c__AnonStorey.observer.OnCompleted();
			//	return Disposable.Empty;
			//}
			//int i = 0;
			//return this.scheduler.Schedule(delegate(Action self)
			//{
			//	if (i < <SubscribeCore>c__AnonStorey.$this.count)
			//	{
			//		int value2 = <SubscribeCore>c__AnonStorey.$this.start + i;
			//		<SubscribeCore>c__AnonStorey.observer.OnNext(value2);
			//		i++;
			//		self();
			//	}
			//	else
			//	{
			//		<SubscribeCore>c__AnonStorey.observer.OnCompleted();
			//	}
			//});
			return null;
		}

		// Token: 0x04000902 RID: 2306
		private readonly int start;

		// Token: 0x04000903 RID: 2307
		private readonly int count;

		// Token: 0x04000904 RID: 2308
		private readonly IScheduler scheduler;

		// Token: 0x020002D2 RID: 722
		private class Range : OperatorObserverBase<int, int>
		{
			// Token: 0x06000F7E RID: 3966 RVA: 0x00047DF3 File Offset: 0x000461F3
			public Range(IObserver<int> observer, IDisposable cancel) : base(observer, cancel)
			{
			}

			// Token: 0x06000F7F RID: 3967 RVA: 0x00047E00 File Offset: 0x00046200
			public override void OnNext(int value)
			{
				try
				{
					this.observer.OnNext(value);
				}
				catch
				{
					base.Dispose();
					throw;
				}
			}

			// Token: 0x06000F80 RID: 3968 RVA: 0x00047E3C File Offset: 0x0004623C
			public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x06000F81 RID: 3969 RVA: 0x00047E74 File Offset: 0x00046274
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}
		}
	}
}
